window.onload = function() {
	seajs.use(['jquery-1.8.2.js', 'iscroll_module.js', 'mdialog_module.js', 'util_module.js'], function(Z, I, M, U) {
		U.fillHead();
		U.fillFooter();
		var id = U.getParam('id');
		var user = U.checkLogin();
		initPage();

		function initPage() { //初始化页面
			U.loadOpt(false);
			initEvent();
		}

		function initEvent() {
			U.ajaxget('/crowd/edit/' + id, {}, function(json) {
				var result = json.models.crowdVO;
				if (result.title == null || result.title == "null") {
					result.title = '众筹捐款详情';
				}
				$('.title').text(result.title)
				$('.name').text(user.info.personVO.name);
				var image = '';
				if (U.getImg(result.images).length > 0) {
					image = U.getImg(result.images)[0]
				}
				$('.donate_content img').attr('src', image);
			});

			$("#union_pay").click(function() {
				$("#union_pay").attr("disabled", "disabled");
				var amount = $("#amount").val();
				var message = $('#message').val();
				if (amount <= 0) {
					alert('请输入正确金额');
					return false;
				}
				var name = user.info.personVO.name;
				//	var content = name == null ? "" : name + " " + title + "  " + $("#help_content").val();
				var support = {
					title: $('.title').text(),
					crowdId: id,
					userId: user.info.id,
					state: 1,
					amount: amount * 100,
					payType: $("input[type='radio']:checked").val(),
					accountType: 2, //1-jjh,2-"xh",
					goodsType: 1,
					message: message,
					username: user.info.personVO.name,
					images: $('.donate_content img').attr('src'),
					device: "pc"
				}
				$.ajax({
					type: "post",
					url: "../../support/add",
					//					data:{"title":"慈善捐款","remark":"张三向协会捐款100", "amount":1, "accountType":"xh"},
					data: support,
					dataType: "json",
					success: function(json) {
						if (json.success) {
							if (json.models.supportRecordVO.payType == 1) {//支付宝
								U.ajax("/alipay/tocwpay", {
									"sign": json.models.supportRecordVO.paySign
								}, function(json) {
									$("#topay").html(json.models.sHtmlText);
									$("#alipaysubmit").submit();
								});
							}
							if (json.models.supportRecordVO.payType == 3) {//银联
								U.ajax("/unionpay/tocwpay", {
									"sign": json.models.supportRecordVO.paySign
								}, function(json) {
									$("#topay").html(json.models.sHtmlText);
									$("#alipaysubmit").submit();
								});
							}
						} else {
							alert(json.errorMsg);
						}
					}
				});
			});

		}
	});
}